//
//  TabBarViewController.m
//  ShangAPP
//
//  Created by macpro on 16/1/21.
//  Copyright © 2016年 wangdao. All rights reserved.
//

#import "TabBarViewController.h"
#import "OrderViewController.h"
#import "ManageViewController.h"
#import "SetViewController.h"
#import "MyTools.h"
#import "SCNavTabBarController.h"
#import "NoOrderViewController.h"
#import "WaitOrderViewController.h"
#import "IngOrderViewController.h"
#import "FinishOrderViewController.h"
#import "MakeOrderViewController.h"
#import "AllOrderViewController.h"


@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    OrderViewController *ovc = [[OrderViewController alloc]init];
    UINavigationController *onc = [[UINavigationController alloc]initWithRootViewController:ovc];
    
    SetViewController *svc = [[SetViewController alloc]init];
    UINavigationController *snc = [[UINavigationController alloc]initWithRootViewController:svc];
    
    //    ManageViewController * mvc =[[ManageViewController alloc]init];
    //    UINavigationController * mnc =[[UINavigationController alloc]initWithRootViewController:mvc];
    
    self.viewControllers = @[onc,snc];
    
    
    AllOrderViewController * allViewController =[[AllOrderViewController alloc]init];
    allViewController.title =@"全部";
    
    NoOrderViewController *oneViewController = [[NoOrderViewController alloc] init];
    oneViewController.title = @"未接单";
    
    WaitOrderViewController *twoViewController = [[WaitOrderViewController alloc] init];
    twoViewController.title = @"待派送";
    
    MakeOrderViewController * makeViewController =[[MakeOrderViewController alloc]init];
    makeViewController.title =@"已接单";
    
    IngOrderViewController *threeViewController = [[IngOrderViewController alloc] init];
    threeViewController.title = @"配送中";
    
    FinishOrderViewController *foueViewController = [[FinishOrderViewController alloc] init];
    foueViewController.title = @"已完成";
    
    SCNavTabBarController *navTabBarController = [[SCNavTabBarController alloc] init];
    navTabBarController.subViewControllers = @[oneViewController,makeViewController,twoViewController,threeViewController,foueViewController,allViewController];
    [navTabBarController addParentController:ovc];
    
//    UIImage *image = [MyTools imageWithColor:[UIColor blackColor] size:CGSizeMake(WIDTH, 49)];
//    [self.navigationController.navigationBar setShadowImage:image];
    
    [self createTaBarItems];
}
- (void)createTaBarItems{
    CGRect frame = CGRectMake(0.0, 0, WIDTH, 49);
    UIView *v = [[UIView alloc] initWithFrame:frame];
    [v setBackgroundColor:UIColorFromRGB(MYColor)];
    [self.tabBar insertSubview:v atIndex:0];
    
    NSArray*selectImageArray=@[@"my_d1.png",@"my_s.png"];
    NSArray*unSelectImageArray=@[@"my_d.png",@"my_s1.png"];
    for (int i = 0; i<unSelectImageArray.count; i++) {
        
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(i*(WIDTH/2), 0, WIDTH/2, 49)];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [button.imageView setContentMode:UIViewContentModeCenter];
        [button setBackgroundImage:[UIImage imageNamed:unSelectImageArray[i]] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:selectImageArray[i]] forState:UIControlStateSelected];
        button.tag = i+100;
        
        [self.tabBar addSubview:button];
        if (i==0) {
            button.selected=YES;
            [button setBackgroundColor:UIColorFromRGB(0x666666)];
            
        }
        
    }
}
- (void)buttonClick:(UIButton *)button{
    for (int i=0; i<2; i++) {
        UIButton*button=(UIButton*)[self.tabBar viewWithTag:100+i];
        button.selected=NO;
        [button setBackgroundColor:UIColorFromRGB(MYColor)];
        
    }
    button.selected=YES;
    self.selectedIndex=button.tag-100;
    [button setBackgroundColor:UIColorFromRGB(0x666666)];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden=YES;
    
    [self.navigationItem setHidesBackButton:YES];
}

@end
